package mk.timska_rabota_android;

import mk.timska_rabota_android.location.LocationModule;
import mk.timska_rabota_android.messages.MessagesModule;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.internal.ay;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
import android.widget.Toast;

public class SendMessage extends Activity {

	private double longitude;
	private double latitude;
	private LocationListener locationListener;
	private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_send_message);
		if(checkPlayServices()){
			//code
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.send_message, menu);
		return true;
	}


	public void locationButton(View v) {
		AutoCompleteTextView lat = (AutoCompleteTextView)findViewById(R.id.latitudeText);
		AutoCompleteTextView lon = (AutoCompleteTextView)findViewById(R.id.longitudeText);
		
		//LocationModule.UpdateLocation(v.getContext(), this);
		//LocationModule.getLastKnownLocation(v.getContext(), this);
		Intent intent = new Intent(this, Map.class);
		intent.putExtra("Longitude", Double.parseDouble(lon.getText().toString()));
		intent.putExtra("Latitude", Double.parseDouble(lat.getText().toString()));
		startActivity(intent);
	}
	
	public void registerButton(View v){
		Context appContext = getApplicationContext();
		
		String registrationId = MessagesModule.getRegistrationId(appContext, this);
		Toast toast = Toast.makeText(getApplicationContext(), registrationId,
				Toast.LENGTH_LONG);
		toast.show();
	}
	
	public boolean checkPlayServices(){
		Context appContext = getApplicationContext();
		int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(appContext);
		if(resultCode != ConnectionResult.SUCCESS){
			if(GooglePlayServicesUtil.isUserRecoverableError(resultCode)){
				GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show();
			} else {
				
				finish();
			}
			return false;
		}
		return true;
	}
	
	public void getServices(View v)
	{
		Context appContext = getApplicationContext();
		Toast ts = Toast.makeText(appContext, "Services will go here", Toast.LENGTH_LONG);
		ts.show();
	}
	

}
